

//
//  XYLocalAlertView.m
//  Zhihuijinfu
//
//  Created by XY Lv on 17/3/27.
//  Copyright © 2017年 王笛. All rights reserved.
//

#import "XYLocalAlertView.h"
#import "XYCommon.h"
@implementation XYLocalAlertView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        self.backgroundColor = [UIColor colorWithRed:0.98 green:0.98 blue:0.98 alpha:1.00];
        [self xyInitSubvies];
    }
    return self;
}

- (void)xyInitSubvies{
    
    _xyIconImgView = [[UIImageView alloc]init];
    [self addSubview:_xyIconImgView];
    [_xyIconImgView setImage:[UIImage imageNamed:@"xy_icon-location"]];
    _xyLocalTextLabel =[[UILabel alloc]init];
    [self addSubview:_xyLocalTextLabel];
    _xyLocalTextLabel.font = [UIFont systemFontOfSize:12];
    _xyLocalTextLabel.textColor = [UIColor colorWithRed:0.37 green:0.62 blue:0.88 alpha:1.00];
    
    UITapGestureRecognizer * xyTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(xyLocalTap:)];
    [self addGestureRecognizer:xyTap];
}

- (void)setXyLocalStr:(NSString *)xyLocalStr{
    _xyLocalStr = xyLocalStr;
    
    CGFloat imgH = xy(10);
    
    CGSize  strSize = [XYCommon xy_getSizeWithStr:xyLocalStr font:[UIFont systemFontOfSize:12] maxSize:CGSizeMake(WDScreenW, MAXFLOAT)];
    CGFloat xyX ;
    if(self.xyAligment == XYLayoutLeft){
        xyX = 0;

    }else if(self.xyAligment == XYLayoutRight){
        xyX = (CGRectGetWidth(self.frame) -  imgH - strSize.width - xyPadding);
    }else{
       xyX = (CGRectGetWidth(self.frame) -  imgH - strSize.width - xyPadding)/2;
 
    }
    
    _xyIconImgView.frame = CGRectMake(xyX,(CGRectGetHeight(self.frame) - imgH)/2, imgH, imgH*(30/24.00));
    
    _xyLocalTextLabel.frame = CGRectMake(CGRectGetMaxX(_xyIconImgView.frame) + xyPadding, 0, strSize.width, CGRectGetHeight(self.frame));
    _xyLocalTextLabel.text = xyLocalStr;
    _xyLocalTextLabel.font = [UIFont systemFontOfSize:12];
}


- (void)xyLocalTap:(UITapGestureRecognizer *)sender{
    if(self.delegate&&[self.delegate respondsToSelector:@selector(xyLocalAlertViewTap:)]){
        [self.delegate xyLocalAlertViewTap:sender.view];
    }
}


@end











